﻿using System;

namespace MonPocGarage.Common.Extensions
{
    public static class EnumExt
    {
        /// <summary>
        /// Converts the String value to an enum of the specified type.
        /// Returns the first type in the enum list if no match found for the String
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumString"></param>
        /// <returns>Enum of Type T</returns>
        public static T ToEnumValue<T>(this string enumString)
        {
            try
            {
                return (T)Enum.Parse(typeof(T), enumString, true);
            }
            catch (Exception)
            {
                return default(T);
            }
        }
    }
}
